"""
@name : 局域网扫描-多进程
@author : FengZT_19
@projectname: python_consumer.py
"""
import IPy
from pythonping import ping
from multiprocessing import Process
import netifaces

# ping
def ping_ip(ip):
    result = ping(ip, timeout=1)
    if result.success():
        print(str(ip) + ":" + "up")
    else:
        print(str(ip) + ":" + "down")

# # ip_net=input("输入网段:")
temp=netifaces.ifaddresses('ens33')[netifaces.AF_INET]
# 获得本机ip地址
ip=temp[0]['addr']
# 获得本机所在网段
ip_net = '.'.join([ip.split('.')[0], ip.split('.')[1], ip.split('.')[2], '0/24'])
# 获得网段内所有ip
ips = IPy.IP(ip_net)
p_lst = []
if __name__=='__main__':
    for ip in ips:
        p = Process(target=ping_ip, args=(str(ip),))
        p_lst.append(p)
        p.start()
    for p in p_lst:
        p.join()
    print("end...")